package com.itasura.redis;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.data.redis.core.StringRedisTemplate;

/**
 * @author sailor wang
 * @date 2018/11/18 11:21 AM
 * @description
 */
@Slf4j
@EnableCaching
@SpringBootApplication
public class RedisApplication implements CommandLineRunner {

    @Autowired
    private StringRedisTemplate stringRedisTemplate;

    public static void main(String[] args) throws InterruptedException {
        SpringApplication.run(RedisApplication.class);
    }

    @Override
    public void run(String... strings) throws Exception {
        log.info("1-消息发送至“teach”主题，内容为:{}", "同学们，上课了！");
        stringRedisTemplate.convertAndSend("teach", "同学们，上课了！");
        log.info("2-消息再次发送至“teach”主题，内容为:={}", "起立，老师好！");
        stringRedisTemplate.convertAndSend("teach", "起立，老师好！");
    }
}
